Skip to content

Fix JDBC parser parameter counting for empty comments and SELECT * EXCEPT - #3067

Open
n200534 wants to merge 1 commit into
ClickHouse:mainfrom
n200534:fix/jdbc-parser-argcount-3052
Open

Fix JDBC parser parameter counting for empty comments and SELECT * EXCEPT#3067
n200534 wants to merge 1 commit into
ClickHouse:mainfrom
n200534:fix/jdbc-parser-argcount-3052

Conversation

@n200534

@n200534 n200534 commented Aug 19, 2026

Copy link
Copy Markdown

Summary

  • fix single-line comment scanning when a bare -- is followed immediately by a newline, so later JDBC parameter markers are still discovered
  • extend the bundled ANTLR4 grammar to accept SELECT * EXCEPT (...), including identifier-list and regular-expression forms
  • add regression coverage for top-level and nested empty comments and SELECT * EXCEPT (...) across all three SQL parser backends
  • document the user-visible fix in CHANGELOG.md

Closes #3052

Root cause

ClickHouseUtils.skipSingleLineComment treated a newline located exactly at its start index as if no newline existed, causing the parameter scanner to skip the rest of the SQL. Separately, the bundled ANTLR4 grammar accepted * in a select list but did not model ClickHouse's EXCEPT modifier, so the parse-tree-based backend never reached a later ? marker.

User impact and compatibility

Prepared statements containing either construct now report the correct parameter count and can bind normally instead of failing with ArrayIndexOutOfBoundsException. This does not change public APIs, configuration, wire protocols, or binary compatibility.

Validation

  • mvn -pl jdbc-v2 -am -DskipTests install — passed under JDK 17
  • mvn -pl jdbc-v2 test — 1,331 tests passed
  • mvn -pl clickhouse-data test — 1,554 tests passed, 113 conditionally skipped, 0 failures/errors

Checklist

@CLAassistant

CLAassistant commented Aug 19, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@n200534
n200534 marked this pull request as ready for review August 19, 2026 22:28
@mshustov
mshustov requested a lite review from Copilot August 20, 2026 16:03
@mshustov

Copy link
Copy Markdown
Member

@cursor review

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes JDBC prepared-statement parameter counting regressions in jdbc-v2 by addressing (1) an off-by-one bug in empty single-line comment skipping and (2) a missing SELECT * EXCEPT (...) construct in the bundled ANTLR4 grammar, which previously caused some parser backends to miss later ? placeholders.

Changes:

  • Fix ClickHouseUtils.skipSingleLineComment(...) to correctly advance past a newline when the comment body is empty (--\n...).
  • Extend the ANTLR4 grammar to parse * EXCEPT (...) in select lists so parse-tree-based JDBC parsers can continue scanning and find later ? markers.
  • Add regression coverage in both clickhouse-data utility tests and jdbc-v2 parser facade tests, and document the user-visible fix in CHANGELOG.md.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.

Show a summary per file
File Description
jdbc-v2/src/test/java/com/clickhouse/jdbc/internal/BaseSqlParserFacadeTest.java Adds regression SQL cases to ensure arg counting remains correct with empty -- lines and SELECT * EXCEPT (...).
jdbc-v2/src/main/antlr4/com/clickhouse/jdbc/internal/parser/antlr4/ClickHouseParser.g4 Updates the ANTLR grammar to allow * select items to include an optional EXCEPT modifier.
clickhouse-data/src/test/java/com/clickhouse/data/ClickHouseUtilsTest.java Adds a focused unit test for skipping an empty -- comment line.
clickhouse-data/src/main/java/com/clickhouse/data/ClickHouseUtils.java Fixes the newline detection condition in skipSingleLineComment(...) so empty comments don’t terminate scanning early.
CHANGELOG.md Documents the jdbc-v2 prepared-statement parameter counting fix and links issue #3052.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit c1daab8. Configure here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

4 participants